#pragma once


#include "基本类型.h"
#include "基础量.h"
//#include <cmath>


/*const float kPi = 3.141592653589f;
const float k2Pi = 2.0f*kPi;
const float kInvPi = 1.0f / kPi;
const float kInv2Pi = 0.5f / kPi;
const float kDegToRad = kPi / 180.0f;
const float kRadToDeg = 180.0f / kPi;*/


inline float32 f_Clamp(float32 V, float32 min, float32 max) {
	V = DEF_Min(max, V);
	V = DEF_Max(min, V);
	return V;
}

//float(1.0/sqrt(x))
Inline float32 f_逆平方根(float32 value) {
	int32 i;
	float32 x2, y;
	const float32 三的一半 = 1.5f;

	x2 = value * 0.5f;
	y = value;
	i = *((int32*)&y);
	i = 0x5f3758df - (i >> 1);
	y = *((float32*)&i);
	y = y * (三的一半 - (x2 * y * y));

	return y;
}



template<typename T>
Inline std::vector<T> range(uint32 s, uint32 e) {
	uint32 num = e - s;
	std::vector<T> data(num);

	for (uint32 i = 0; i < num; ++i) {
		data[i] = i;
	}

	return data;
}



#define DEF_FOR_赋值(var, num, 值) for (uint32 i = 0; i < num; ++i) ((var)[i]) = (值);




/*CUDA_CALLABLE inline float32 f_DegToRad(float32 t)
{
	return t * kDegToRad;
}

CUDA_CALLABLE inline float32 f_RadToDeg(float32 t)
{
	return t * kRadToDeg;
}

CUDA_CALLABLE inline float32 f_Sin(float32 theta)
{
	return sinf(theta);
}

CUDA_CALLABLE inline float32 f_Cos(float32 theta)
{
	return cosf(theta);
}

CUDA_CALLABLE inline void f_SinCos(float32 theta, float32& s, float32& c)
{
	// no optimizations yet
	s = sinf(theta);
	c = cosf(theta);
}

CUDA_CALLABLE inline float32 f_Tan(float32 theta)
{
	return tanf(theta);
}

CUDA_CALLABLE inline float32 f_Sqrt(float32 x)
{
	return sqrtf(x);
}

CUDA_CALLABLE inline float64 f_Sqrt(float64 x)
{
	return sqrt(x);
}

CUDA_CALLABLE inline float32 f_ASin(float32 theta)
{
	return asinf(theta);
}

CUDA_CALLABLE inline float32 f_ACos(float32 theta) {
	return acosf(theta);
}

CUDA_CALLABLE inline float32 f_ATan(float32 theta) {
	return atanf(theta);
}

CUDA_CALLABLE inline float32 f_ATan2(float32 x, float32 y) {
	return atan2f(x, y);
}

CUDA_CALLABLE inline float32 f_Abs(float32 x) {
	return fabsf(x);
}

CUDA_CALLABLE inline float32 f_Pow(float32 b, float32 e) {
	return powf(b, e);
}




CUDA_CALLABLE inline float32 f_Sgn(float x) {
	return (x < 0.0f ? -1.0f : 1.0f);
}

CUDA_CALLABLE inline float f_Sign(float x) {
	return x < 0.0f ? -1.0f : 1.0f;
}

CUDA_CALLABLE inline double f_Sign(double x) {
	return x < 0.0f ? -1.0f : 1.0f;
}

CUDA_CALLABLE inline float f_Mod(float x, float y) {
	return fmod(x, y);
}


template <typename T>
CUDA_CALLABLE inline T f_Min(T a, T b) {
	return a < b ? a : b;
}

template <typename T>
CUDA_CALLABLE inline T f_Max(T a, T b) {
	return a > b ? a : b;
}



template <typename T>
CUDA_CALLABLE inline void f_Swap(T& a, T& b) {
	T tmp = a;
	a = b;
	b = tmp;
}



template <typename T>
CUDA_CALLABLE inline T f_Clamp(T a, T low, T high) {
	if (low > high)
		f_Swap(low, high);

	return f_Max(low, f_Min(a, high));
}



template <typename V, typename T>
CUDA_CALLABLE inline V f_Lerp(const V& start, const V& end, const T& t) {
	return start + (end - start)*t;
}

CUDA_CALLABLE inline float f_InvSqrt(float x) {
	return 1.0f / sqrtf(x);
}

// round towards +infinity
CUDA_CALLABLE inline int f_Round(float f) {
	return int(f + 0.5f);
}



template <typename T>
CUDA_CALLABLE T f_Normalize(const T& v) {
	T a(v);
	a /= f_Length(v);
	return a;
}

template <typename T>
CUDA_CALLABLE inline typename T::value_type f_LengthSq(const T v) {
	return Dot(v, v);
}

template <typename T>
CUDA_CALLABLE inline typename T::value_type f_Length(const T& v) {
	typename T::value_type lSq = LengthSq(v);
	if (lSq)
		return f_Sqrt(LengthSq(v));
	else
		return 0.0f;
}

// this is mainly a helper function used by script
template <typename T>
CUDA_CALLABLE inline typename T::value_type f_Distance(const T& v1, const T& v2) {
	return f_Length(v1 - v2);
}

template <typename T>
CUDA_CALLABLE inline T SafeNormalize(const T& v, const T& fallback = T()) {
	float l = f_LengthSq(v);
	if (l > 0.0f) {
		return v * f_InvSqrt(l);
	}
	else return fallback;
}

template <typename T>
CUDA_CALLABLE inline T f_Sqr(T x) { return x * x; }

template <typename T>
CUDA_CALLABLE inline T f_Cube(T x) { return x * x * x; }








template <typename T>
CUDA_CALLABLE inline T f_平方(T value) {
	return value * value;
}

*/









